package cn.zhz.cloud.auth.web.controller;

import cn.zhz.cloud.auth.web.service.IPermissionService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.zhz.cloud.common.model.result.R;
import cn.zhz.cloud.auth.web.model.dto.PermissionQueryDto;
import cn.zhz.cloud.auth.web.model.dto.PermissionSaveDto;
import cn.zhz.cloud.auth.web.model.vo.PermissionVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 权限 Controller
 * @author zhz
 * @since 2022-11-08
 */
@RestController
@RequestMapping("/permission")
@RequiredArgsConstructor
@Api(tags = "权限 接口集合")
public class PermissionController {

    private final IPermissionService iPermissionService;


    @ApiOperation(value = "分页查询", notes = "")
    @GetMapping(value = "/page")
    public R<Page<PermissionVo>> page(PermissionQueryDto queryDto) {
        return R.ok(iPermissionService.page(queryDto));
    }

    @ApiOperation(value = "详情", notes = "")
    @GetMapping(value = "/info/{id}")
    public R<PermissionVo> info(@Valid @NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        return R.ok(iPermissionService.info(id));
    }

    @ApiOperation(value = "保存", notes = "新增&&修改")
    @PostMapping(value = "/save")
    public R<String> save(@Valid @RequestBody PermissionSaveDto saveDto) {
        return R.ok(String.valueOf(iPermissionService.save(saveDto)));
    }

    @ApiOperation(value = "删除", notes = "")
    @PostMapping(value = "/delete/{id}")
    public R<Void> delete(@Valid @NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        iPermissionService.delete(id);
        return R.ok();
    }

}
